package com.sl.au.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.InventoryReduce;

@Transactional(readOnly = true)
public interface InventoryReduceRepository extends JpaRepository<InventoryReduce, String> {
	/**
	 * 根据Key得数据
	 * 
	 * @param key
	 * @param pageable
	 * @return
	 */
	@Query(" select i from InventoryReduce i where i.material like '%'+?1+'%' or i.name like '%'+?1+'%' or i.figureNum like '%'+?1+'%' or i.user.empLogin.name like '%'+?1+'%' ")
	Page<InventoryReduce> findInventoryReduce(String key, Pageable pageable);

	// 根据key得数据条数
	@Query(" select count(*) from InventoryReduce i where i.material like '%'+?1+'%' or i.name like '%'+?1+'%' or i.figureNum like '%'+?1+'%' or i.user.empLogin.name like '%'+?1+'%' ")
	long findCount(String key);

	@Query(" select i from InventoryReduce i where i.quoteDevice.id=?1 ")
	Page<InventoryReduce> getIsReplace(String quoteDeviceId, Pageable pageable);

	@Query(" select count(*) from InventoryReduce i where i.quoteDevice.id=?1 ")
	Long findIsReplaceCount(String quoteDeviceId);

	/**
	 * 得到InventoryReduce ByQuoteDeviceId
	 * 
	 * @param quoteDeviceId
	 * @return
	 */
	@Query(" select i from InventoryReduce i where i.quoteDevice.id=?1 ")
	List<InventoryReduce> findByQuoteDeviceId(String quoteDeviceId);
}
